package com.admin;


import com.Constants;
import com.admin.DepartmentAction;


import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;








public class DepartmentAction extends UserService {
	

	/**
	 * 
	 */
	private static final long serialVersionUID = -3882495706167829719L;
	private int Comid;
	private int Deptid;
	private int Sjid;
	private String Deptname;
	private String Xgzd;
	private String Value;
	private  String table="\"Department\"";
	private int Userid;
	


@SuppressWarnings({ "rawtypes", "unchecked" })
public void getdeptxx() {
	
	Map map=new HashMap();
	map.put("table", "\"User_Department\" a");
	map.put("jointable", " join \"Department\" b on a.\"Deptid\"=b.\"Deptid\" and b.\"Status\"=0");
	map.put("where", "a.\"Userid\"="+Userid+"");
	map.put("nr", "b.*");
	map.put("px", "b.\"Deptid\"");
	List<LinkedHashMap<String, String>>	list =selecttable(map);
	ajaxJsontable(list);	
	
}





	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void dotoshowdeptabe() {
		if(Comid!=0) {
			
			Map map=new HashMap();
			map.put("table", table);
			map.put("where", "\"Comid\"="+Comid+" and \"Status\"!=9999 and \"Sjid\"=0");
			map.put("nr", "*");
			map.put("px", "\"Deptid\"");
			List<LinkedHashMap<String, String>>	list =selecttable(map);
			ajaxJsontable(list);	
		}else if(Deptid!=0) {
			Map map=new HashMap();
			map.put("table", table);
			map.put("where", "\"Sjid\"="+Deptid+" and \"Status\"!=9999");
			map.put("nr", "*");
			map.put("px", "\"Deptid\"");
			List<LinkedHashMap<String, String>>	list =selecttable(map);
			ajaxJsontable(list);
			
			
		}else {
			
			ajaxJsontablefy("0",null);
		}
		
	}
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void savedeptnew() {
		Map map=new HashMap();
		map.put("table", table);
		map.put("where", "\"Status\"!=9999 and "+"\"Sjid\"="+Sjid+" and \"Comid\"="+Comid+" and \"Deptname\"='"+Deptname+"'");
		map.put("nr", "*");
		map.put("px", "\"Deptid\"");
		List<LinkedHashMap<String, String>>	list =selecttable(map);
		if(list.size()>0) {
			ajaxJson("部门名称重复");
			savelog("部门名称重复,操作失败");
		}else {
			User user=(User)session.get(Constants.USER);
		map.put("zdm", "\"Createuserid\",\"Deptname\",\"Comid\",\"Sjid\"");	
		map.put("nr", user.getUserid()+",'"+Deptname+"',"+Comid+","+Sjid);	
		inserttable(map);	
		ajaxJson("保存成功");
		savelog("保存成功");	
			
		}
		
		
	}
	
	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void xgdept() {
		Map map=new HashMap();
		map.put("table", table);
		if(Xgzd.equals("Deptname")) {
			
			
			
			map.put("where", "\"Status\"!=9999 and "+"\"Sjid\"="+Sjid+" and \"Comid\"="+Comid+" and \"Deptname\"='"+Value+"'");
			map.put("nr", "*");
			map.put("px", "\"Deptid\"");
			List<LinkedHashMap<String, String>>	list =selecttable(map);
			if(list.size()>0) {
				ajaxJson("1");
				savelog("部门名称重复,操作失败");
				return;
			}
			
		}
		
			map.put("Xgzd", Xgzd);
			map.put("Value", Value);
			map.put("Keyid", "Deptid");
			map.put("Keyidvalue", Deptid);
			updatetablebykey(map);
		ajaxJson("操作成功");
		savelog("操作成功");	
			
		
		
		
		
	}
	
	@SuppressWarnings("unchecked")
	public  int getdepnumber(int comid) {
		
		@SuppressWarnings("rawtypes")
		Map map=new HashMap();
		map.put("table", table);
		map.put("nr", "*");
		map.put("px", "\"Deptid\"");
		
		if(comid!=0) {
			map.put("where", "\"Status\"!=9999 and  \"Comid\"="+comid);
				
			
		}else {
			
			map.put("where", "\"Status\"!=9999");
			
			
		}
		List<LinkedHashMap<String, String>>	list =selecttable(map);
		return list.size();
	}
	
	
	public int getComid() {
		return Comid;
	}
	public void setComid(int comid) {
		Comid = comid;
	}
		
	public int getDeptid() {
		return Deptid;
	}

	public void setDeptid(int deptid) {
		Deptid = deptid;
	}

	public int getSjid() {
		return Sjid;
	}

	public void setSjid(int sjid) {
		Sjid = sjid;
	}

	public String getDeptname() {
		return Deptname;
	}

	public void setDeptname(String deptname) {
		Deptname = deptname;
	}

	public String getXgzd() {
		return Xgzd;
	}


	public void setXgzd(String xgzd) {
		Xgzd = xgzd;
	}

	public String getValue() {
		return Value;
	}


	public void setValue(String value) {
		Value = value;
	}





	public int getUserid() {
		return Userid;
	}





	public void setUserid(int userid) {
		Userid = userid;
	}
	
}